<?php
namespace app\common\controller;
trait Mine{
    /**
     * 获取我账下的微信号
     * @return [type] [description]
     */
    function getMineSoft($isJson=false){
        if($isJson||request()->isAjax()||request()->isPost()){
            $uid=$this->user['id'];
            $list=model('software')->readAll(['member_id'=>$uid],0,['field'=>'number']);
            $data=[];
            foreach ($list as $v) {
                $data[]=$v['number'];
            }
            $data=array_unique($data);
            sort($data);
            if($isJson){
                return json('',0,$data);
            }
            $this->success('','',$data);
        }
    }
    /**
     * 获取为查询的手机号码
     * @return [type] [description]
     */
    function getminetel($isJson=false){
        if($isJson||request()->isAjax()||request()->isPost()){
            $uid=$this->user['id'];
            $list=model('mobile')->readAll(['member_id'=>$uid,'status'=>0],0,['field'=>'tel']);
            $data=[];
            foreach ($list as $v) {
                $data[]=$v['tel'];
            }
            $data=array_unique($data);
            sort($data);
            if($isJson){
                return json('',0,$data);
            }
            $this->success('','',$data);
        }
    }
    /**
     * 获取账号库中的微信号
     * @return [type] [description]
     */
    function getmineWX($isJson=false){
        if($isJson||request()->isAjax()||request()->isPost()){
            $uid=$this->user['id'];
            $list=model('mobile')->readAll(['member_id'=>$uid,'status'=>1],0,['field'=>'weixin']);
            $data=[];
            foreach ($list as $v) {
                $data[]=$v['weixin'];
            }
            $data=array_unique($data);
            sort($data);
            if($isJson){
                return json('',0,$data);
            }
            $this->success('','',$data);
        }
    }
    /**
     * 获取我的群组
     * @return [type] [description]
     */
    function getMineWxGroup($soft=[],$devs=[],$isJson=false){
        if($isJson||request()->isAjax()||request()->isPost()){
            $uid=$this->user['id'];
            if(is_string($soft)){
                $soft=json_decode($soft,true);
            }
            
            if(empty($soft)){
                if(is_string($devs)){
                    $devs=json_decode($devs,true);
                }
                $devices=model('software')->readAll(
                    [
                        'member_id'=>$uid,
                        'device_id'=>['device_id','in',$devs]
                    ],
                    0,
                    ['field'=>'id']
                );
                foreach ($devices as $v) {
                    $soft[]=$v['id'];
                }
            }
            $map=[
                'member_id'=>$uid,
                'type'=>1,
                'soft_id'=>['soft_id','in',$soft]
            ];
            $list=model('social')->readAll($map,0,['field'=>'name']);

            $data=[];
            foreach ($list as $v) {
                $data[]=$v['name'];
            }
            $data=array_unique($data);
            sort($data);
            if($isJson){
                return json('',0,$data);
            }
            $this->success('','',$data);
        }
    }
    /**
     * 获取我的好友
     * @return [type] [description]
     */
    function getMineSocial($soft=[],$devs=[],$isJson=false){
        if($isJson||request()->isAjax()||request()->isPost()){
            $uid=$this->user['id'];
            if(is_string($soft)){
                $soft=json_decode($soft,true);
            }
            if(empty($soft)){
                if(is_string($devs)){
                    $devs=json_decode($devs,true);
                }
                $devices=model('software')->readAll(
                    [
                        'member_id'=>$uid,
                        'device_id'=>['device_id','in',$devs]
                    ],
                    0,
                    ['field'=>'id']
                );
                foreach ($devices as $v) {
                    $soft[]=$v['id'];
                }
            }
            $map=[
                'member_id'=>$uid,
                'type'=>0,
                'soft_id'=>['soft_id','in',$soft]
            ];
            $list=model('social')->readAll($map,0,['field'=>'name']);
            $data=[];
            foreach ($list as $v) {
                $data[]=$v['name'];
            }
            $data=array_unique($data);
            sort($data);
            if($isJson){
                return json('',0,$data);
            }
            $this->success('','',$data);
        }
    }
    /**
     * 获取我的好友
     * @return [type] [description]
     */
    function getMine($soft=[],$devs=[],$isJson=false,$type=0){
        if($isJson||request()->isAjax()||request()->isPost()){
            $uid=$this->user['id'];
            if(is_string($soft)){
                $soft=json_decode($soft,true);
            }
            if(empty($soft)){
                if(is_string($devs)){
                    $devs=json_decode($devs,true);
                }
                $devices=model('software')->readAll(
                    [
                        'member_id'=>$uid,
                        'device_id'=>['device_id','in',$devs]
                    ],
                    0,
                    ['field'=>'id']
                );
                foreach ($devices as $v) {
                    $soft[]=$v['id'];
                }
            }
            $map=[
                'member_id'=>$uid,
                'type'=>$type,
                'soft_id'=>['soft_id','in',$soft]
            ];
            $list=model('social')->readAll($map,0,['field'=>'name']);

            $data=[];
            foreach ($list as $v) {
                $data[]=$v['name'];
            }
            $data=array_unique($data);
            sort($data);
            if($isJson){
                return json('',0,$data);
            }
            $this->success('','',$data);
        }
    }
}